package ns.om.services

import ns.gflex.domain.*;
import ns.gflex.domain.association.*;
import ns.gflex.services.InitService;
import ns.om.domain.dict.*;
import ns.om.domain.project.*;

/**
 * Functions
 * @since Dec 22, 2010
 * @author wangchu
 */
class OmInitService extends InitService {
	def init(){
		super.init();
		appendGflex();
		
		ReqStatus.init();
		Complexity.init();
		EffortUnit.init();
		Priority.init();
		TaskStatus.init();
	}
	
	private void appendGflex(){
		def roleAdmin = Role.findByRoleCode('Administrators')
		def roleProject = new Role(roleName:'项目管理员',roleCode:'ProjectManager',editable:false,description:'内置角色：项目管理员。').save()
		Long rootId = Menu.findByParentIdIsNull().id

		def project = new Menu(label:'需求管理',app:'',displayOrder:20,parentId:rootId).save()
		[
			new Menu(label:'产品',app:'ProductList',displayOrder:1,parentId:project.id),
			new Menu(label:'项目',app:'ProjectList',displayOrder:2,parentId:project.id),
			new Menu(label:'需求',app:'ReqList',displayOrder:3,parentId:project.id),
			new Menu(label:'缺陷',app:'BugList',displayOrder:4,parentId:project.id)
		].each{
			it.save()
			new RoleMenu(role:roleAdmin,menu:it).save()
			new RoleMenu(role:roleProject,menu:it).save()
		}
		
		def type =  ParamType.findByCode('system')
		def admin = User.findByAccount('admin')
		new Param(code:'DefaultEffortUnit',name:'默认工作量单位',value:'天',type:type,validExp:'^(小时|天|月)$',validDescribe:'小时 天 月',lastUser:admin).save()		
	}
}
